//package com.fox.lazy.config;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.SpringApplication;
//import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
//import org.springframework.boot.context.event.ApplicationFailedEvent;
//import org.springframework.boot.context.event.ApplicationPreparedEvent;
//import org.springframework.boot.context.event.ApplicationStartingEvent;
//import org.springframework.context.ApplicationContext;
//import org.springframework.context.event.ContextClosedEvent;
//import org.springframework.core.Ordered;
//import org.springframework.core.env.Environment;
//
//import org.slf4j.MDC;
//import org.springframework.context.ApplicationEvent;
//import org.springframework.context.event.GenericApplicationListener;
//import org.springframework.core.ResolvableType;
//import org.springframework.stereotype.Component;
//import org.springframework.util.StringUtils;
//
//import javax.servlet.http.HttpServletRequest;
//
///**
// * 我没问题，有问题就是别人的问题！
// *
// * @author 何杰
// * @since 2021/4/19 17:10
// */
//
//@Component
//public class ApplicationStartedEventListener implements GenericApplicationListener {
//
//    private static final int DEFAULT_ORDER = Ordered.HIGHEST_PRECEDENCE + 10;
//
//    private static Class<?>[] EVENT_TYPES = {ApplicationStartingEvent.class,
//            ApplicationEnvironmentPreparedEvent.class, ApplicationPreparedEvent.class,
//            ContextClosedEvent.class, ApplicationFailedEvent.class};
//
//    private static Class<?>[] SOURCE_TYPES = {SpringApplication.class,
//            ApplicationContext.class};
//
//    @Autowired
//    private Environment env;
//
//    @Override
//    public void onApplicationEvent(ApplicationEvent applicationEvent) {
//        //获取请求链路 通过请求头 trace-id
//        String appName = env.getProperty("spring.application.name");
//        if (!StringUtils.isEmpty(appName)) {
//            MDC.put("service", appName);
//        }
//        String active = env.getProperty("spring.profiles.active");
//        if (!StringUtils.isEmpty(active)) {
//            MDC.put("active", active);
//        }
//    }
//
//    @Override
//    public boolean supportsEventType(ResolvableType resolvableType) {
//        return false;
//    }
//}
